package com.yoshon.yoshonapp.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.text.TextUtils;

import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class StringUtils {
	/**
	 * 处理空字符串
	 *
	 * @param str
	 * @return String
	 */
	public static String doEmpty(String str) {
		return doEmpty(str, "");
	}

	/**
	 * 处理空字符串
	 *
	 * @param str
	 * @param defaultValue
	 * @return String
	 */
	public static String doEmpty(String str, String defaultValue) {
		if (str == null || str.equalsIgnoreCase("null")
				|| str.trim().equals("") || str.trim().equals("－请选择－")) {
			str = defaultValue;
		} else if (str.startsWith("null")) {
			str = str.substring(4, str.length());
		}
		return str.trim();
	}
	/**
	 * 判断给定字符串是否空白串。
	 * 空白串是指由空格、制表符、回车符、换行符组成的字符串
	 * 若输入字符串为null或空字符串，返回true
	 * @param input
	 * @return boolean
	 */
	public static boolean isEmpty( String input )
	{
		if ( input == null || "".equals( input ) )
			return true;

		for ( int i = 0; i < input.length(); i++ )
		{
			char c = input.charAt( i );
			if ( c != ' ' && c != '\t' && c != '\r' && c != '\n' )
			{
				return false;
			}
		}
		return true;
	}


	/**
	 * 检查字符串是否为空
	 *
	 * @param str
	 *            字符串
	 * @return
	 */
	public static boolean isNotEmpty(String str) {
		return !isEmpty(str);
	}

	public static String[] split(String str, String splitsign) {
		int index;
		if (str == null || splitsign == null) {
			return null;
		}
		ArrayList al = new ArrayList();
		while ((index = str.indexOf(splitsign)) != -1) {
			al.add(str.substring(0, index));
			str = str.substring(index + splitsign.length());
		}
		al.add(str);
		return (String[]) al.toArray(new String[0]);
	}

	public static String replace(String from, String to, String source) {
		if (source == null || from == null || to == null)
			return null;
		StringBuffer str = new StringBuffer("");
		int index = -1;
		while ((index = source.indexOf(from)) != -1) {
			str.append(source.substring(0, index) + to);
			source = source.substring(index + from.length());
			index = source.indexOf(from);
		}
		str.append(source);
		return str.toString();
	}

	private static final String _BR = "";

	public static String htmlshow(String str) {
		if (str == null) {
			return null;
		}

		str = replace("<", "<", str);
		str = replace(" ", " ", str);
		str = replace("\r\n", _BR, str);
		str = replace("\n", _BR, str);
		str = replace("\t", "    ", str);
		return str;
	}

	public static String toLength(String str, int length) {
		if (str == null) {
			return null;
		}
		if (length <= 0) {
			return "";
		}
		try {
			if (str.getBytes("GBK").length <= length) {
				return str;
			}
		} catch (Exception e) {
		}
		StringBuffer buff = new StringBuffer();

		int index = 0;
		char c;
		length -= 3;
		while (length > 0) {
			c = str.charAt(index);
			if (c < 128) {
				length--;
			} else {
				length--;
				length--;
			}
			buff.append(c);
			index++;
		}
		buff.append("...");
		return buff.toString();
	}

	public static boolean isInteger(String str) {
		Pattern pattern = Pattern.compile("^[-\\+]?[\\d]+$");
		return pattern.matcher(str).matches();
	}

	public static boolean isDouble(String str) {
		Pattern pattern = Pattern.compile("^[-\\+]?\\d+\\.\\d+$");
		return pattern.matcher(str).matches();
	}

	public static boolean isLetter(String str) {
		if (str == null || str.length() < 0) {
			return false;
		}
		Pattern pattern = Pattern.compile("[\\w\\.-_]*");
		return pattern.matcher(str).matches();
	}

	public static String parse(String content) {
		String email = null;
		if (content == null || content.length() < 1) {
			return email;
		}
		// 找出含有@
		int beginPos;
		int i;
		String token = "@";
		String preHalf = "";
		String sufHalf = "";

		beginPos = content.indexOf(token);
		if (beginPos > -1) {
			// 前项扫描
			String s = null;
			i = beginPos;
			while (i > 0) {
				s = content.substring(i - 1, i);
				if (isLetter(s))
					preHalf = s + preHalf;
				else
					break;
				i--;
			}
			// 后项扫描
			i = beginPos + 1;
			while (i < content.length()) {
				s = content.substring(i, i + 1);
				if (isLetter(s))
					sufHalf = sufHalf + s;
				else
					break;
				i++;
			}
			// 判断合法性
			email = preHalf + "@" + sufHalf;
			if (isEmail(email)) {
				return email;
			}
		}
		return null;
	}

	/** 验证邮箱  */
	public static boolean isEmail(String email) {
		if (email == null || email.length() < 1 || email.length() > 256) {
			return false;
		}
		Pattern pattern = Pattern
				.compile("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$");
		return pattern.matcher(email).matches();
	}

	/** 验证手机号  */
	public static boolean isMobile(String str) {
		Pattern p = null;
		Matcher m = null;
		boolean b = false;

		p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
		m = p.matcher(str);
		b = m.matches();

		return b;

	}


	public static boolean isBlank(String str) {
		return str == null || str.trim().length() == 0;
	}

	public static boolean isPrime(int x) {
		if (x <= 7) {
			if (x == 2 || x == 3 || x == 5 || x == 7)
				return true;
		}
		int c = 7;
		if (x % 2 == 0)
			return false;
		if (x % 3 == 0)
			return false;
		if (x % 5 == 0)
			return false;
		int end = (int) Math.sqrt(x);
		while (c <= end) {
			if (x % c == 0) {
				return false;
			}
			c += 4;
			if (x % c == 0) {
				return false;
			}
			c += 2;
			if (x % c == 0) {
				return false;
			}
			c += 4;
			if (x % c == 0) {
				return false;
			}
			c += 2;
			if (x % c == 0) {
				return false;
			}
			c += 4;
			if (x % c == 0) {
				return false;
			}
			c += 6;
			if (x % c == 0) {
				return false;
			}
			c += 2;
			if (x % c == 0) {
				return false;
			}
			c += 6;
		}
		return true;
	}

	public static String hangeToBig(String str) {
		double value;
		try {
			value = Double.parseDouble(str.trim());
		} catch (Exception e) {
			return null;
		}
		char[] hunit = { '拾', '佰', '仟' }; // 段内位置表示
		char[] vunit = { '万', '亿' }; // 段名表示
		char[] digit = { '零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖' }; // 数字表示
		long midVal = (long) (value * 100); // 转化成整形
		String valStr = String.valueOf(midVal); // 转化成字符串

		String head = valStr.substring(0, valStr.length() - 2); // 取整数部分
		String rail = valStr.substring(valStr.length() - 2); // 取小数部分

		String prefix = ""; // 整数部分转化的结果
		String suffix = ""; // 小数部分转化的结果
		// 处理小数点后面的数
		if (rail.equals("00")) { // 如果小数部分为0
			suffix = "整";
		} else {
			suffix = digit[rail.charAt(0) - '0'] + "角"
					+ digit[rail.charAt(1) - '0'] + "分"; // 否则把角分转化出来
		}
		// 处理小数点前面的数
		char[] chDig = head.toCharArray(); // 把整数部分转化成字符数组
		char zero = '0'; // 标志'0'表示出现过0
		byte zeroSerNum = 0; // 连续出现0的次数
		for (int i = 0; i < chDig.length; i++) { // 循环处理每个数字
			int idx = (chDig.length - i - 1) % 4; // 取段内位置
			int vidx = (chDig.length - i - 1) / 4; // 取段位置
			if (chDig[i] == '0') { // 如果当前字符是0
				zeroSerNum++; // 连续0次数递增
				if (zero == '0') { // 标志
					zero = digit[0];
				} else if (idx == 0 && vidx > 0 && zeroSerNum < 4) {
					prefix += vunit[vidx - 1];
					zero = '0';
				}
				continue;
			}
			zeroSerNum = 0; // 连续0次数清零
			if (zero != '0') { // 如果标志不为0,则加上,例如万,亿什么的
				prefix += zero;
				zero = '0';
			}
			prefix += digit[chDig[i] - '0']; // 转化该数字表示
			if (idx > 0)
				prefix += hunit[idx - 1];
			if (idx == 0 && vidx > 0) {
				prefix += vunit[vidx - 1]; // 段结束位置应该加上段名如万,亿
			}
		}

		if (prefix.length() > 0)
			prefix += '圆'; // 如果整数部分存在,则有圆的字样
		return prefix + suffix; // 返回正确表示
	}

	@SuppressWarnings("unused")
	private static String removeSameString(String str) {
		Set mLinkedSet = new LinkedHashSet();// set集合的特征：其子集不可以重复
		String[] strArray = str.split(" ");// 根据空格(正则表达式)分割字符串
		StringBuffer sb = new StringBuffer();

		for (int i = 0; i < strArray.length; i++) {
			if (!mLinkedSet.contains(strArray[i])) {
				mLinkedSet.add(strArray[i]);
				sb.append(strArray[i] + " ");
			}
		}
//		System.out.println(mLinkedSet);
		return sb.toString();
	}

	public static String encoding(String src) {
		if (src == null)
			return "";
		StringBuilder result = new StringBuilder();
		if (src != null) {
			src = src.trim();
			for (int pos = 0; pos < src.length(); pos++) {
				switch (src.charAt(pos)) {
					case '"':
						result.append("\"");
						break;
					case '<':
						result.append("<");
						break;
					case '>':
						result.append(">");
						break;
					case '\'':
						result.append("'");
						break;
					case '&':
						result.append("&");
						break;
					case '%':
						result.append("&pc;");
						break;
					case '_':
						result.append("&ul;");
						break;
					case '#':
						result.append("&shap;");
						break;
					case '?':
						result.append("&ques;");
						break;
					default:
						result.append(src.charAt(pos));
						break;
				}
			}
		}
		return result.toString();
	}

	public static boolean isHandset(String handset) {
		try {
			String regex = "^1[\\d]{10}$";
			Pattern pattern = Pattern.compile(regex);
			Matcher matcher = pattern.matcher(handset);
			return matcher.matches();

		} catch (RuntimeException e) {
			return false;
		}
	}

	public static String decoding(String src) {
		if (src == null)
			return "";
		String result = src;
		result = result.replace("\"", "\"").replace("'", "\'");
		result = result.replace("<", "<").replace(">", ">");
		result = result.replace("&", "&");
		result = result.replace("&pc;", "%").replace("&ul", "_");
		result = result.replace("&shap;", "#").replace("&ques", "?");
		return result;
	}

	public static String zeroFill(String liuShuiHao, String STR_FORMAT) {
		Integer intHao = Integer.parseInt(liuShuiHao);
		DecimalFormat df = new DecimalFormat(STR_FORMAT);
		return df.format(intHao);
	}

	// 判断字符串是否包含有中文
	public static boolean isChinese(String str) {
		String regex = "[\\u4e00-\\u9fa5]";
		Pattern pattern = Pattern.compile(regex);
		Matcher matcher = pattern.matcher(str);
		return matcher.find();
	}


	//将毫秒转化为日期格式
	public static String parseDateUtil(long time)
	{
		String nowtime;
//		SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日");
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

		Calendar calendar = Calendar.getInstance();
		calendar.setTimeInMillis(time);
		nowtime= formatter.format(calendar.getTime());
//		Date d = new Date(time);
//		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//		 sdf.format(d);
		return nowtime;
	}


	/**
	 * 密码是否为8位以上的数字字母混合，如果是返回true
	 * @param password
	 * @return
	 */
	public static boolean regPassword(String password){
		Pattern p = Pattern.compile("(?i)^(?![a-z]+$)(?![0-9]+$)[a-z0-9]{8,}$");
		Matcher m = p.matcher(password);
		return m.matches();
	}


	/**
	 *
	 * @Title: getSmallImgSrc
	 * @Description: 将传入的互动大图片转换成后缀为_small的小图片
	 * @param @param bigImgs
	 * @param @return    设定文件
	 * @return List<String>    返回类型
	 * @throws
	 */
	public static List<String> getSmallImgSrc(List<String> bigImgs){
		List<String> srcs = new ArrayList<String>();
		try {
			for (String src : bigImgs) {

				String lastName = src.substring(src.lastIndexOf("."));
				String replaceName = lastName.replace(".", "_small.");
				srcs.add(src.replace(lastName, replaceName));

			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return srcs;
	}




	/**
	 * 转换毫秒数成“分、秒”，如“01:53”。若超过60分钟则显示“时、分、秒”，如“01:01:30
	 *
	 * @param time 待转换的毫秒数
	 * */
	public static String converLongTimeToStr(long time) {
		int ss = 1000;
		int mi = ss * 60;
		int hh = mi * 60;

		long hour = (time) / hh;
		long minute = (time - hour * hh) / mi;
		long second = (time - hour * hh - minute * mi) / ss;

		String strHour = hour < 10 ? "0" + hour : "" + hour;
		String strMinute = minute < 10 ? "0" + minute : "" + minute;
		String strSecond = second < 10 ? "0" + second : "" + second;
		if (hour > 0) {
			return strHour + ":" + strMinute + ":" + strSecond;
		} else {
			return strMinute + ":" + strSecond;
		}
	}



	private final static ThreadLocal<SimpleDateFormat> dateFormater = new ThreadLocal<SimpleDateFormat>() {
		@Override
		protected SimpleDateFormat initialValue() {
			return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		}
	};

	private final static ThreadLocal<SimpleDateFormat> dateFormater2 = new ThreadLocal<SimpleDateFormat>() {
		@Override
		protected SimpleDateFormat initialValue() {
			return new SimpleDateFormat("yyyy-MM-dd");
		}
	};

	/**
	 * 将字符串转位日期类型
	 *
	 * @param sdate
	 * @return
	 */
	public static Date toDate(String sdate) {
		try {
			return dateFormater.get().parse(sdate);
		} catch (ParseException e) {
			return null;
		}
	}

	/**
	 * 以友好的方式显示时间
	 *
	 * @param sdate
	 * @return
	 */
	public static String friendly_time(String sdate) {
		Date time = toDate(sdate);
		if (time == null) {
			return "Unknown";
		}
		String ftime = "";
		Calendar cal = Calendar.getInstance();

		// 判断是否是同一天
		String curDate = dateFormater2.get().format(cal.getTime());
		String paramDate = dateFormater2.get().format(time);
		if (curDate.equals(paramDate)) {
			int hour = (int) ((cal.getTimeInMillis() - time.getTime()) / 3600000);
			if (hour == 0)
				ftime = Math.max(
						(cal.getTimeInMillis() - time.getTime()) / 60000, 1)
						+ "分钟前";
			else
				ftime = hour + "小时前";
			return ftime;
		}

		long lt = time.getTime() / 86400000;
		long ct = cal.getTimeInMillis() / 86400000;
		int days = (int) (ct - lt);
		if (days == 0) {
			int hour = (int) ((cal.getTimeInMillis() - time.getTime()) / 3600000);
			if (hour == 0)
				ftime = Math.max(
						(cal.getTimeInMillis() - time.getTime()) / 60000, 1)
						+ "分钟前";
			else
				ftime = hour + "小时前";
		} else if (days == 1) {
			ftime = "昨天";
		} else if (days == 2) {
			ftime = "前天";
		} else if (days > 2 && days <= 10) {
			ftime = days + "天前";
		} else if (days > 10) {
			ftime = dateFormater2.get().format(time);
		}
		return ftime;
	}

	/**
	 * 判断是否为空串
	 *
	 * @param str
	 *            需要判断的 字符串
	 * @return true不为空；false为""或者null
	 */
	public static boolean isNotBlank(String str) {
		return str != null && !"".equals(str.trim());
	}

	/**
	 * 判断一个String是否为数字
	 *
	 * @param str
	 *            要判断的String串
	 * @return 是数字返回true，否则返回false;
	 */
	public static boolean isNum(String str) {
		if (isBlank(str)) {
			return false;
		}
		try {
			Pattern p = Pattern.compile("[0-9]+(\\.[0-9]+)?");
			Matcher m = p.matcher(str);
			if (m.matches()) {
				return true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	/**
	 * 判断一个String是否为int数据
	 *
	 * @param str
	 *            要判断的String串
	 * @return 是数字返回true，否则返回false;
	 */
	/*public static boolean isInteger(String str) {
		if (isBlank(str)) {
			return false;
		}
		try {
			Integer.parseInt(str);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}*/

	/**
	 * 返回一个小数点后p位的string
	 */
	public static String getNum(double d, int p) {
		if (p < 0) {
			p = 0;
		}
		return String.format("%." + p + "f", d);
	}

	/**
	 * 判断一个String是否为小数
	 *
	 * @param str
	 *            要判断的String串
	 * @return 是小数返回true，否则返回false;
	 */
	public static boolean isDecimal(String str) {
		if (isBlank(str)) {
			return false;
		}
		try {
			Pattern p = Pattern.compile("[0-9]+\\.{1}[0-9]+");
			Matcher m = p.matcher(str);
			if (m.matches()) {
				return true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	/**
	 * 去除字符串中的空格、回车、换行符、制表符
	 *
	 * @param str  String
	 * @return
	 */
	public static String getStringWithoutEnter(String str) {
		String dest = "";
		if (str != null) {
			Pattern p = Pattern.compile("\\s*|\t|\r|\n");
			Matcher m = p.matcher(str);
			dest = m.replaceAll("");
		}
		return dest;
	}

	/**
	 * 获取指定长度的随机数
	 *
	 * @param length 要获取的随机数长度
	 * @return 获取的结果
	 */
	public static String getRandom(int length) {
		int tmp = 1;
		if (length <= 0) {
			return "";
		}
		for (int i = 0; i < length; i++) {
			tmp = tmp * 10;
		}
		int temp = (int) (tmp * Math.random());
		while (temp == 0 || temp == 100) {
			temp = (int) (tmp * Math.random());
		}
		return temp + "";
	}

	/**
	 * 将数字保留两位小数
	 *
	 * @param number
	 * @return
	 */
	public static String parseNumber(double number) {
		DecimalFormat df = new DecimalFormat("#0.00");
		return df.format(number);
	}

	public static String parseNumberOne(double number){
		DecimalFormat df = new DecimalFormat("#0.0");
		df.setRoundingMode(RoundingMode.HALF_UP);
		return df.format(number);
	}

	public static String ToDBC(String input) {
		char[] c = input.toCharArray();
		for (int i = 0; i< c.length; i++) {
			if (c[i] == 12288) {
				c[i] = (char) 32;
				continue;
			}if (c[i]> 65280&& c[i]< 65375)
				c[i] = (char) (c[i] - 65248);
		}
		return new String(c);
	}

	public static String[] getToday(){
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		String date=sdf.format(new java.util.Date());
		String[] day = new String[2];
		day[0] = date+" 00:00:00";
		day[1] = date+" 23:59:59";
		return day;
	}

	/**
	 * 传入一个数字，如果大于99则返回99+，否则返回"num"
	 *
	 * @param num 数字类型
	 * @return
	 */
	public static String numCeiling(Integer num) {
		if (num > 99) {
			return 99 + "+";
		}
		return String.valueOf(num);
	}

	/*
	 *
	 * 毫秒转化时分秒毫秒
	 *  毫秒现在是转换为小时。如需要全部:解开注释
	 */
	public static String formatTime(Long ms) {
		Integer ss = 1000;
		Integer mi = ss * 60;
		Integer hh = mi * 60;
		Integer dd = hh * 24;

		Long day = ms / dd;
		Long hour = (ms - day * dd) / hh;
		Long minute = (ms - day * dd - hour * hh) / mi;
		Long second = (ms - day * dd - hour * hh - minute * mi) / ss;
		Long milliSecond = ms - day * dd - hour * hh - minute * mi - second * ss;

		StringBuffer sb = new StringBuffer();
	    /*if(day > 0) {
	        sb.append(day+"天");
	    }
	    */
		if(hour > 0) {
			//sb.append(hour+"小时");
			sb.append(hour);
		}
	    /*
	    if(minute > 0) {
	        sb.append(minute+"分");
	    }
	    if(second > 0) {
	        sb.append(second+"秒");
	    }
	    if(milliSecond > 0) {
	        sb.append(milliSecond+"毫秒");
	    }
	    */
		return sb.toString();
	}
	/**
	 * 验证手机格式
	 */
	public static boolean isMobileNO(String mobiles) {
		/*
		移动：134、135、136、137、138、139、150、151、157(TD)、158、159、187、188
		联通：130、131、132、152、155、156、185、186
		电信：133、153、180、189、（1349卫通）
		总结起来就是第一位必定为1，第二位必定为3或5或8，其他位置的可以为0-9
		*/
		String telRegex = "[1][358]\\d{9}";//"[1]"代表第1位为数字1，"[358]"代表第二位可以为3、5、8中的一个，"\\d{9}"代表后面是可以是0～9的数字，有9位。
		if (TextUtils.isEmpty(mobiles)) return false;
		else return mobiles.matches(telRegex);
	}

	/**
	 * 判断手机是否安装了微信
	 *
	 * boolean
	 */
	public static boolean isWeixinAvilible(Context context) {
		final PackageManager packageManager = context.getPackageManager();// 获取packagemanager
		List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);// 获取所有已安装程序的包信息
		if (pinfo != null) {
			for (int i = 0; i < pinfo.size(); i++) {
				String pn = pinfo.get(i).packageName;
				if (pn.equals("com.tencent.mm")) {
					return true;
				}
			}
		}

		return false;
	}

	/**
	 *
	 * @Title: formatVer
	 * @Description: 转化用户学时方法
	 * @param @param ver
	 * @param @return    设定文件
	 * @return float    返回类型
	 * @throws
	 */
	public static float formatVer(String ver)
	{
		float  b=0.0f;
		if(ver!=null&&!"".equals(ver)){

			b   =  (float)(Math.round(Float.parseFloat(ver)*10))/10;
		}

		return b;
	}

	/**
	 * 字符串截取位数  替换成  *
	 *  UserName 字符串（姓名）
	 *  Uend 字符串长度
	 * boolean
	 */
	public static String strNameReplace(String UserName,int Uend) {
		String mNewUserNameB = UserName.substring(0, Uend-1);////最后一位的前面所有字符
		String mNewUserNameE = UserName.substring(Uend-1,Uend);//最后一位字符
		StringBuffer strbuffer=new StringBuffer();
		for (int j = 0; j < mNewUserNameB.length(); j++) {
			strbuffer.append("*");
		}
		String newS = strbuffer.toString();
		newS="**";//取前面两个
		String mNewUserName=newS+mNewUserNameE;//最终用户名替换的后的字符串

		return mNewUserName;
	}

	/**
	 * 字符串截取位数  替换成  *
	 *  Name 字符串（电话号码 5/员工编号 4）
	 *  Nend 字符串长度
	 *  count 前后需要显示几个可见的数
	 *  phone 那个类型 截取*
	 * boolean
	 */
	public static String strPhoneReplace(String Name,int Nend,int count,String phone) {
		String mNewNameB = Name.substring(0,count);//前几位字符
		String mNewNameE = Name.substring(Nend-count, Nend);//后几位字符
		String mNewNameC = Name.substring(count, Nend-count);//中间的位字符
		StringBuffer strbuffermob = new StringBuffer();
		for (int j = 0; j < mNewNameC.length(); j++) {
			strbuffermob.append("*");
		}
		String newM = strbuffermob.toString();
		if ("P".equals(phone)) {//手机号码时 截取5个*
			newM = "*****";
		} else {
			newM = "****";;//员工编号时 截取4个*
		}

		String mNewName =mNewNameB+newM+mNewNameE;//最终电话号码替换的后的字符串
		return mNewName;
	}

	/**
	 * 严格的检查手机号码是否是正确的格式
	 * boolean
	 */
	public static boolean isMobileStr(String mobiles){
		Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
		Matcher m = p.matcher(mobiles);
		System.out.println(m.matches()+"---");
		return m.matches();
	}

	/**
	 * 将string中的某一项换到第一位
	 * @param totalStr  初始string
	 * @param str  换到第一位的string
	 * @return 最终需要的string
	 */
	public static String dedup(String totalStr,String str,int i){
		if(i == 0){
			return totalStr;
		}else {
			int num = totalStr.indexOf(","+str+",");
			String lastStr = str+","+totalStr.substring(0, num)+totalStr.substring(num + str.length()+1);
			return lastStr;
		}

	}

}